import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'

import {localTime} from '../../utils/date'
import './index.scss'

class TopicItem extends Component{
  handleGoDetail(item){
    Taro.navigateTo({url: '/pages/detail/index?topicid=' + item.id})
  }
  render(){
    let {item} = this.props
    return(
      <View className='topic-item' onClick={this.handleGoDetail.bind(this, item)}>
        <Image className='user-img' src={item.author ? item.author.avatar_url: ''} />
        <View className='topic-item-right'>
          <View className='item-right-title'>
            {item.top ? <Text className='topic-up'>置顶</Text> : (item.tab === 'share' ? <Text className='topic-up blue'>分享</Text> : <Text className='topic-up blue'>问答</Text>)}
            <Text>{item.title}</Text>
          </View>
          <View className='item-right-bottom'> 
            <Text>{item.loginname}</Text>
            <Text>{item.reply_count}/{item.visit_count}</Text>
            <Text>创建时间{localTime(item.create_at)}</Text>
          </View>
        </View>
      </View>
    )
  }
}

TopicItem.defaultProps = {
  item: {}
}

export default TopicItem